import 'package:aio/aio.dart';
import 'package:app/src/http/bean/clockin/clock_in.dart';

import 'attendances.dart';

///经纬度坐标和范围
class ClokinPointRange extends BaseBean {
  String? BaiduMapPoint = null; //"121.537442,29.934031"; //打卡设置的经纬度
  String? CompanyName = ""; //打卡签到的公司名称
  String? SignInRange = "1000"; //考勤范围，单位米
  List<MyGroupBcInfo>? GroupBcInfo = null; //班组

  ClockinInfo? WorkInfo = null; //上班下班打卡记录;服务器返回的是最新的一条记录。

  ///判断当前状态是否为正在上班的状态。 true 已经上班打过卡。下班未打卡。
  bool isOnWork() {
    return WorkInfo?.isOnWork() ?? false;
  }

  ///判断是否已经下班打卡;(主要判断当天是否已经下班打过卡)
  bool isOffWork() {
    return WorkInfo?.isOffWork() ?? false;
  }

  double _SignInRange = 0;

  //获取考勤范围
  double getSignInRange() {
    if (_SignInRange > 0) {
      return _SignInRange;
    }
    if (StringUtils.isNotEmpty(SignInRange)) {
      try {
        _SignInRange = double.parse(SignInRange!);
      } catch (e) {}
    }
    return _SignInRange;
  }

  double? _latitude = null;

  //获取纬度
  double? getLatitude() {
    if (_latitude != null) {
      return _latitude;
    } else if (BaiduMapPoint != null) {
      var strList = BaiduMapPoint?.split(",");
      if (strList != null && strList.length >= 2) {
        try {
          _longitude = double.parse(strList[0].trim());
          _latitude = double.parse(strList[1].trim());
        } catch (e) {}
      }
    }
    return _latitude;
  }

  double? _longitude;

  //获取经度
  double? getLongitude() {
    if (_longitude != null) {
      return _longitude;
    } else if (BaiduMapPoint != null) {
      var strList = BaiduMapPoint?.split(",");
      if (strList != null && strList.length >= 2) {
        try {
          _longitude = double.parse(strList[0].trim());
          _latitude = double.parse(strList[1].trim());
        } catch (e) {}
      }
    }
    return _longitude;
  }

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    BaiduMapPoint = json["BaiduMapPoint"]?.toString();
    CompanyName = json["CompanyName"]?.toString();
    SignInRange = json["SignInRange"]?.toString();
    GroupBcInfo = setGenericFromJson(
        json, 'GroupBcInfo', <MyGroupBcInfo>[], MyGroupBcInfo());
    WorkInfo = setGenericFromJson(json, 'WorkInfo', ClockinInfo(), "");
  }

  @override
  instance() {
    // TODO: implement instance
    return ClokinPointRange();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["BaiduMapPoint"] = BaiduMapPoint;
    map["CompanyName"] = CompanyName;
    map["SignInRange"] = SignInRange;
    map["GroupBcInfo"] = GroupBcInfo;
    map["WorkInfo"] = WorkInfo;
    return map;
  }
}
